<?php
/**
 * Created by PhpStorm.
 * User: dingjinlai
 * Date: 2019/4/10
 * Time: 下午3:58
 */

class Ali
{

    public function pu_goods($url)
    {

        $url_arr = parse_url($url);
        $url_path = explode('/', $url_arr['path']);
        $itemid = str_replace('.html','',$url_path[2]);
        if ($itemid) {
            $api_url = 'https://api03.6bqb.com/alibaba/app/detail?apikey=C09B58B9F947417E22C64F762A1E57F9&itemId='.$itemid;
            return $this->Ali_curl($api_url);
        }

        // if ($itemid) {//CB96B44171207C5336BF9189FBF70890
        //     $api_url = 'http://api03.6bqb.com/alibaba/detail?apikey=C09B58B9F947417E22C64F762A1E57F9&itemid='.$itemid;
        //     return $this->Ali_curl($api_url);
        // }



    }
    public function Ali_curl($url, $post_data = array(), $method = 'GET')
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        if ($post_data) {
            $data_string = json_encode($post_data);

            $headers = array(
                "Content-Type: application/json",
                "Accept: application/json",
                "Content-Length:" . strlen($data_string)
            );

            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true);

        $content = curl_exec($ch);

        curl_close($ch);

        return json_decode($content, true);
    }
}
